package com.group.three.service.impl;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.group.three.mapper.VideoTagMapper;
import com.group.three.pojo.VideoTag;
import com.group.three.service.VideoTagService;
import com.group.three.utils.SnowFlakeUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;


@Service
public class VideoTagServiceImpl implements VideoTagService {

    @Autowired
    VideoTagMapper videoTagMapper;


    /**
     * 分页查询 Tag
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageInfo<VideoTag> selectAllTag(Integer pageNum, Integer pageSize) {
        //        开启分页
        Page<Object> objects = PageHelper.startPage(pageNum, pageSize);
        //        开启查询所有,配合分页插件
        List<VideoTag> productorders = videoTagMapper.selectAllTag(pageNum,pageSize);
        PageInfo<VideoTag> pageInfo =new PageInfo<VideoTag>(productorders,pageNum);
        return pageInfo;
    }



    @Override
    public boolean deleteTagByTagId(Long TagId) {
        int i = videoTagMapper.deleteTagByTagId(TagId);
        if (i!=0){
            return true;
        }else {
            return false;
        }
    }

    @Override
    public List<VideoTag> selectByVideoTag(Long videoTag) {
        List<VideoTag> tag = videoTagMapper.selectByVideoTag(videoTag,1);
        return tag;
    }

    /**
     * 搜素标签
     * @param inputText 关键词
     * @return
     */
    @Override
    public List<VideoTag> searchByVideoTag(String inputText) {
        return videoTagMapper.searchByVideoTag(inputText);
    }

    /**
     * 添加新标签
     * @param inputData
     * @param userName
     * @return
     */
    @Override
    public boolean addNewTag(String inputData, String userName,String ip) {
        VideoTag videoTag =new VideoTag(SnowFlakeUtil.getSnowFlakeId(),inputData,
                new Date(),userName,1,ip);
        int addNewTag = videoTagMapper.addNewTag(videoTag);
        if (addNewTag!=0){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 更具管理员名称或者tag名称查询
     * @param inputText
     * @return
     */
    @Override
    public List<VideoTag> searchTagLogByUserNameOrTagName(String inputText) {
        return videoTagMapper.searchTagLogByUserNameOrTagName(inputText);
    }

    /**
     * 根据tag名字精确查找id
     * @param tag
     * @return
     */
    @Override
    public Long selectTagIdByTagName(String tag) {
        return videoTagMapper.selectTagIdByTagName(tag,1);
    }


}
